package com.codefish.framework.spring.context;

import com.codefish.framework.spring.beans.exception.BeansException;
import com.codefish.framework.spring.beans.factory.config.IBeanFactoryPostProcessor;
import com.codefish.framework.spring.beans.factory.config.IConfigurableListableBeanFactory;
import com.codefish.framework.spring.context.event.IApplicationListener;

import java.io.Closeable;
import java.io.IOException;

/**
 * 可配置的ApplicationContext
 * @author <a href='https://gitee.com/hzf2281'>codefish</a>
 * @version 1.0.0
 * @since 2022/10/04 上午 09:49
 */
public interface IConfigurableApplicationContext extends IApplicationContext, Closeable {

    String SHUTDOWN_HOOK_THREAD_NAME = "SpringContextShutdownHook";

    /**
     * 从xml加载bean以及其它配置，初始化beanFactory
     *
      * @throws BeansException  beanFactory初始化失败时抛出
     * @throws IllegalStateException applicationContext已经初始化过且不允许重复初始化时抛出
     */
    void refresh() throws BeansException, IllegalStateException;

    /**
     * 添加BeanFactoryPostProcessor
     * @param postProcessor 待添加的BeanFactoryPostProcessor
     */
    void addBeanFactoryPostProcessor(IBeanFactoryPostProcessor postProcessor);

    /**
     * 获取内部的beanFactory
     * @return 内部的beanFactory
     * @throws IllegalStateException 如果当前的context不包含beanFactory时抛出
     */
     IConfigurableListableBeanFactory getBeanFactory() throws IllegalStateException;

    /**
     * 注册虚拟机结束的生命周期钩子
     */
    void registerShutdownHook();

    /**
     * 添加监听者
     *
     * @param applicationListener 待添加的监听者
     */
    void addApplicationListener(IApplicationListener<?> applicationListener);


    /**
     * 关闭ApplicationContext
     *
     */
    @Override
    void close();
}
